//
// Created by 高森森 on 2022/10/8.
//

#ifndef LEETCODE_SOLUTION_15_H
#define LEETCODE_SOLUTION_15_H
#include<bits/stdc++.h>
using namespace std;

class solution_15 {
    vector<vector<int>> imageSmoother(vector<vector<int>>& img) {
        int x=img.size();
        int y=img[0].size();
        vector<vector<int>>result(x,vector<int>(y,0));
        int count;
        for(int i=0;i<x;i++){
            for(int j=0;j<y;j++){
                count=0;
                for(int nx=i-1;nx<=i+1;nx++){
                    for(int ny=j-1;ny<=j+1;ny++){
                        if(nx>=0&&nx<x&&ny>=0&&ny<y)
                        {
                            result[i][j]+=img[nx][ny];
                            count++;
                        }
                    }
                }
                result[i][j]=result[i][j]/count;
            }
        }
        return result;
    }
};


#endif //LEETCODE_SOLUTION_15_H
